﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game.Foundation.ChineseChess
{
    public class Ju : ChessmanBase
    {
        public Ju(Chessboard board, Camp camp, string text) : base(board, camp, text) { }

        public override bool CanMoveTo(int xLocation, int yLocation)
        {
            int xoffset = xLocation - this.XLocation;
            int yoffset = yLocation - this.YLocation;
            if (xoffset * yoffset == 0)
            {
                if (xoffset == 0)
                {
                    for (int begin = this.YLocation + yoffset / Math.Abs(yoffset); begin != yLocation; begin += yoffset / Math.Abs(yoffset))
                    {
                        if (this._board.GetChessman(this.XLocation, begin) != null)
                        {
                            return false;
                        }
                    }

                    return true;
                }
                else
                {
                    for (int begin = this.XLocation + xoffset / Math.Abs(xoffset); begin != xLocation; begin += xoffset / Math.Abs(xoffset))
                    {
                        if (this._board.GetChessman(begin, this.YLocation) != null)
                        {
                            return false;
                        }
                    }

                    return true;
                }
            }

            return false;
        }
    }
}
